package com.aopStudy.advice;

import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/*
增强类，添加事物
 */
@Component
@Aspect
@Order(20)
public class TxAdvice {

    @Before("com.aopStudy.pointcut.MyPointcut.myPointCut().myPointcut()")
    public void begin() {
        System.out.println("开启事务");
    }

    @AfterReturning(value = "com.aopStudy.pointcut.MyPointcut.myPointCut().myPointcut()", returning = "returnValue")
    public void commit(Object returnValue) {
        System.out.println("事务提交，返回值：" + returnValue);
    }

    @AfterThrowing(value = "com.aopStudy.pointcut.MyPointcut.myPointCut().myPointcut()", throwing = "throwable")
    public void rollback(Throwable throwable) {
        System.out.println("事务回滚，" + throwable);
    }


}
